//
//  NSView+Ext.swift
//  TTCOM-macOS
//
//  Created by Toj on 1/21/21.
//

import Foundation

@objc 
public extension NSView {
    
    var tt_backgroundColor: NSColor? {
        set {
            if !wantsLayer { wantsLayer = true }
            layer?.backgroundColor = newValue?.cgColor
        }
        get {
            let color = layer?.backgroundColor ?? .clear
            return NSColor(cgColor: color)
        }
    }
    
    func tt_cornerRadius(_ radius : CGFloat) {
        self.wantsLayer = true
        self.layer?.cornerRadius = radius
        self.layer?.masksToBounds = true
    }
    
    func tt_border(color : NSColor, width : CGFloat = 1) {
        self.wantsLayer = true
        self.layer?.borderColor = color.cgColor
        self.layer?.borderWidth = width
    }
    
    
    func tt_shadow(color : NSColor?, opacity : Float = 1, radius : CGFloat = 10 ) {
        self.wantsLayer = true
        let shadow = NSShadow()
        shadow.shadowColor = color
        shadow.shadowBlurRadius = radius
        self.shadow = shadow
    }
}
